<template>
  <view>
    <u-popup
      class="resume-deliver-container"
      v-model="showPopupDialog"
      @close="handleClose"
      mode="bottom"
      width="100%"
      closeable
    >
      <view class="container">
        <view class="text1"> 简历投递 </view>
        <view class="text2"> 请选择您要投递的简历 </view>
        <view> </view>

        <view
          @click="handleUploadAttachResume"
          class="card-attachment-resume"
          v-if="attachmentFileList.length <= 0"
        >
          <view class="card-attachment-resume-box1">
            附件简历 <span class="recomment"> 推荐 </span>
          </view>
          <view class="card-attachment-resume-text2">
            点击上传简历文件，直接投递岗位
          </view>
        </view>

        <view
          class="attachment-item"
          v-for="(item, index) in attachmentFileList"
          :key="index"
        >
          <view class="file-img"> </view>

          <view class="center-box">
            <view class="file-name text-overflow"> {{ item.attName }} </view>
            <view class="file-size"> {{ item.filesize }} </view>
          </view>

          <view class="delivery" @click="handleClickDelivery(item)">
            投递
          </view>
        </view>

        <view
          class="upload-attach-resume"
          v-if="attachmentFileList.length <= 2 && attachmentFileList.length > 0"
          @click="handleUploadAttachResume"
        >
          <img class="upload-attach-resume-img" />
          <!-- <u-image width="30rpx" height="28rpx" :src="uploadAttachFileImg"></u-image>
            -->
          <view class="upload-attach-resume-text"> 上传附件简历 </view>
        </view>

        <view
          class="card-online-resume"
          @click="handleCompleteOnlineResume"
          v-if="!isOnlineResumeComplete && attachmentFileList.length <= 0"
        >
          <view class="card-online-resume-box1">
            <view class="online-text"> 在线简历</view>
            <view class="defect-text"> 缺少“教育背景”、“工作经历” </view>
          </view>
          <view class="complete"> 去完善 </view>
        </view>

        <view
          @click="handleCompleteOnlineResume"
          class="online-resume-uncomplete-box"
          v-if="!isOnlineResumeComplete && attachmentFileList.length > 0"
        >
          您的在线简历未完善，点击
          <span class="edit-online-resume"> 编辑在线简历 </span>
        </view>
      </view>
    </u-popup>
  </view>
</template>
<script>
import { resumeDeliveryNew, checkResumeCompleteNew } from '@/api/index';
export default {
  props: {
    isShowPop: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      uploadAttachFileImg:
        'https://img3.job1001.com/ypMp/elan/images/resume/img_upload_attach_resume2.png',
      // 附件简历列表
      attachmentFileList: [],
      // 在线简历是否已经完善
      isOnlineResumeComplete: false,
      showPopupDialog: false,

      companyId: undefined,
      positionId: undefined,
      jobName: undefined,
      personId: undefined,
      activityId: '',
      source: 'gaoxiaosaas' // 默认是从高校SaaS页面进来
    };
  },
  created() {},

  methods: {
    verify() {
      uni.showLoading({
        title: '请等待',
        mask: false
      });
      // [{"title":"","content":"","company":"cm1293527382304","position":"53591647","job":"","user":"23575442","wage":"","tjsalarArr"：{"resend":"1","attachResumeSendId":""}}]
      var data = [
        {
          title: '求职信',
          content: '贵公司，您好，我基本符合以上职位的条件，应聘该职，谢谢！',
          company: this.companyId,
          position: this.positionId,
          job: this.jobName,
          user: this.personId,
          wage: 0,
          tjsalarArr: {
            resend: 1,
            attachResumeSendId: ''
          },
          activityId: this.activityId,
          source: this.source
        }
      ];
      checkResumeCompleteNew({ data: JSON.stringify(data) })
        .then((res) => {
          uni.hideLoading();
          var _data = res;
          if (_data.code == 200) {
            uni.showToast({
              icon: 'none',
              title: '申请成功'
            });
            this.$emit('deliverySuccess');
            //this.info.can_apply = 0;
          } else if (_data.code == 400 && _data.data) {
            /**
              * 提示弹框 
              * IsComplete 1表示在线简历完善 2不完善 
              * isHaveAttach 1存在附件 2有附件
                lostStr 在线简历缺少资料提示
             */

            var tempAttachList = _data.data.attachList || [];
            if (tempAttachList.length >= 3) {
              tempAttachList = tempAttachList.slice(0, 3);
            }
            this.attachmentFileList = tempAttachList;
            this.isOnlineResumeComplete = _data.data.IsComplete == 1;
            this.setVisibility(true);
          } else {
            // 投递失败
            uni.showToast({
              title: _data.status_desc,
              icon: 'none'
            });
          }
        })
        .catch((err) => {
          uni.hideLoading();
        });
    },

    // 投递简历校验
    verifyResumeDelivery({
      companyId,
      positionId,
      jobName,
      personId,
      activityId,
      source
    }) {
      this.companyId = companyId;
      this.positionId = positionId;
      this.jobName = jobName;
      this.personId = personId;
      this.activityId = activityId;
      this.source = source;

      var that = this;
      uni.showModal({
        title: '温馨提示',
        content: '确认申请该职位吗？',
        success: function (res) {
          if (res.confirm) {
            that.verify();
          } else if (res.cancel) {
          }
        }
      });
    },

    handleClickDelivery(item) {
      uni.showLoading({
        title: '投递中',
        mask: false
      });
      var data = [
        {
          title: encodeURIComponent('求职信'),
          content: encodeURIComponent(
            '贵公司，您好，我基本符合以上职位的条件，应聘该职，谢谢！'
          ),
          company: this.companyId,
          position: this.positionId,
          job: encodeURIComponent(this.jobName),
          user: this.personId,
          wage: 0,
          tjsalarArr: {
            resend: 1,
            attachResumeSendId: item.id || ''
          },
          activityId: this.activityId,
          source: this.source
        }
      ];
      resumeDeliveryNew({ data: JSON.stringify(data) })
        .then((res) => {
          uni.hideLoading();
          this.setVisibility(false);
          if (
            res.code == 200 &&
            Array.isArray(res.data) &&
            res.data.length > 0
          ) {
            var _data = res.data[0];
            if (_data.code == 200) {
              uni.showToast({
                icon: 'none',
                title: '申请成功'
              });

              this.$emit('deliverySuccess');
            } else {
              // 投递失败
              uni.showToast({
                title: _data.status_desc,
                icon: 'none'
              });
            }
          } else {
            // 投递失败
            uni.showToast({
              title: res.status_desc,
              icon: 'none'
            });
          }
        })
        .catch((err) => {
          uni.hideLoading();
          this.setVisibility(false);
        });
    },

    getCurrentPersonId() {
      return uni.getStorageSync('person-id').slice(2) || undefined;
    },

    // 点击 跳转到 上传附件简历页面
    handleUploadAttachResume() {
      var personId = this.getCurrentPersonId();
      if (!personId) {
        this.$emit('showLoginDialog');
        return;
      }
      // this.addBuryingPointFn(20013);
      uni.navigateTo({
        url: '/pagesSub/userCenter/enclosure/index'
      });
    },

    // 点击完善在线简历
    handleCompleteOnlineResume() {
      var personId = this.getCurrentPersonId();
      if (!personId) {
        this.$emit('showLoginDialog');
        return;
      }
      uni.navigateTo({
        url: '/pagesSub/newResume/index'
      });
    },

    setVisibility(visibility) {
      this.showPopupDialog = visibility;
    },

    handleClose() {
      this.showPopupDialog = false;
    },

    closeDialog() {
      this.showPopupDialog = false;
    }
  }
};
</script>
<style lang="scss" scoped>
.resume-deliver-container {
  .container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-left: 40rpx;
    padding-right: 32rpx;

    .text1 {
      display: flex;
      flex-direction: row;
      align-items: center;
      margin-top: 28rpx;
      justify-content: center;
      font-size: 32rpx;
      color: #333333;
    }
    .text2 {
      width: 100%;
      font-weight: 400;
      font-size: 28rpx;
      color: #555555;
      margin-bottom: 32rpx;
      margin-top: 40rpx;
    }
    .card-attachment-resume {
      width: 100%;
      background: #ffffff;
      border-radius: 8rpx;
      border: 1rpx solid #dfdfdf;
      padding-left: 32rpx;
      padding-right: 32rpx;
      padding-bottom: 40rpx;
      padding-top: 40rpx;
      display: flex;
      flex-direction: column;
      // align-items: center;
      margin-bottom: 24rpx;
      &-box1 {
        width: 100%;
        display: flex;
        flex-direction: row;
        font-weight: 500;
        font-size: 32rpx;
        color: #222222;
        .recomment {
          margin-left: 24rpx;
          width: 84rpx;
          height: 40rpx;
          font-size: 26rpx;
          color: #f04646;
          background: #ffeeee;
          border-radius: 8rpx;
          display: flex;
          flex-direction: row;
          justify-content: center;
          align-items: center;
        }
      }
      &-text2 {
        margin-top: 8rpx;
      }
    }

    .upload-attach-resume {
      width: 100%;
      height: 72rpx;
      background: #ffffff;
      border-radius: 8rpx;
      border: 1rpx solid #dfdfdf;
      display: flex;
      flex-direction: row;
      justify-content: center;
      align-items: center;
      margin-bottom: 32rpx;
      &-text {
        font-weight: 400;
        font-size: 28rpx;
        color: #555555;
        margin-left: 18rpx;
      }
      .upload-attach-resume-img {
        width: 30rpx;
        height: 28rpx;

        background-image: url($img-base + 'resume/img_upload_attach_resume3.png');
        background-size: 100% 100%;
        background-repeat: no-repeat;
      }
    }

    .attachment-item {
      width: 100%;
      background: #ffffff;
      border-radius: 8rpx;
      border: 1rpx solid #dfdfdf;
      display: flex;
      flex-direction: row;
      align-items: center;
      padding-left: 32rpx;
      padding-right: 32rpx;
      padding-top: 28rpx;
      padding-bottom: 28rpx;
      margin-bottom: 24rpx;

      .file-img {
        width: 64rpx;
        height: 68rpx;

        background-image: url($img-base + 'resume/img_attach_file.png');
        background-size: 100% 100%;
        background-repeat: no-repeat;
      }
      .center-box {
        flex: 1;
        margin-left: 32rpx;
        
        .file-name {
          width: 360rpx;
          font-weight: 500;
          font-size: 28rpx;
          color: #222222;
        }
        .file-size {
          margin-top: 8rpx;
          font-weight: 400;
          font-size: 24rpx;
          color: #999999;
        }
      }
      .delivery {
        display: flex;
        flex-direction: row;
        justify-content: center;
        align-items: center;
        width: 120rpx;
        height: 60rpx;
        background: #f04646;
        border-radius: 8rpx;
        font-weight: 400;
        font-size: 28rpx;
        color: #ffffff;
      }
    }

    .card-online-resume {
      width: 100%;
      display: flex;
      flex-direction: row;
      align-items: center;
      margin-bottom: 40rpx;
      background: #ffffff;
      border-radius: 8rpx;
      border: 1rpx solid #dfdfdf;
      padding-left: 32rpx;
      padding-right: 32rpx;
      padding-top: 40rpx;
      padding-bottom: 40rpx;
      &-box1 {
        flex: 1;
        .online-text {
          font-weight: 500;
          font-size: 32rpx;
          color: #222222;
        }
        .defect-text {
          margin-top: 8rpx;
          font-weight: 400;
          font-size: 28rpx;
          color: #999999;
        }
      }

      .complete {
        width: 148rpx;
        height: 60rpx;
        background: #ffffff;
        border-radius: 8rpx;
        border: 2rpx solid #f04646;
        font-weight: 400;
        font-size: 28rpx;
        color: #f04646;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
      }
    }
    .online-resume-uncomplete-box {
      font-weight: 400;
      font-size: 24rpx;
      color: #999999;
      width: 100%;
      padding-bottom: 40rpx;
      .edit-online-resume {
        color: #f04646;
        margin-bottom: 40rpx;
      }
    }
  }
}
</style>
